package com.yyn.Learning.controller;


import com.yyn.Learning.entity.EduTeacher;
import com.yyn.Learning.entity.vo.TeacherQuery;
import com.yyn.Learning.service.EduTeacherService;
import com.yyn.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 讲师 前端控制器
 * </p>
 *
 * @author yyn
 * @since 2022-11-08
 */
@Slf4j
@Api("讲师管理")
@RestController
@CrossOrigin  //解决跨域问题
@RequestMapping("/Learning/teacher")
public class EduTeacherController {
    @Autowired
    private EduTeacherService eduTeacherService;

    //    查询讲师表所有数据
    @ApiOperation("查询所有老师")
    @GetMapping("/findAll")
    public R findAllTeacher() {
        List<EduTeacher> list = eduTeacherService.list(null);
        return R.success().data("items", list);
    }

    //    分页
    @ApiOperation("分页查询")
    @PostMapping("/page/{page}/{pageSize}")
    public R page(@PathVariable Long page, @PathVariable int pageSize, @RequestBody(required = false) TeacherQuery teacherQuery) {
        return eduTeacherService.page(page, pageSize, teacherQuery);
    }
    @ApiOperation("删除讲师")
    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable String id) {
        return eduTeacherService.dele(id);
    }

    @ApiOperation("新增讲师")
    @PostMapping("/addTeacher")
    public R save(@RequestBody EduTeacher eduTeacher) {
        return eduTeacherService.insert(eduTeacher);
    }

    @ApiOperation("更新讲师")
    @PostMapping("/editTeacher")
//    修改是前端把信息传过来给后端
    public R update(@RequestBody EduTeacher eduTeacher) {
        return eduTeacherService.upDate(eduTeacher);
    }

    @ApiOperation("通过id查询")
    @GetMapping("/getThisTeacher/{id}")

//    查询是前端通过路径把id传给后端 后端再返回信息回去（都是通过参数json来的）
    public R selectById(@PathVariable String id) {
        return eduTeacherService.selectById(id);
    }
    @GetMapping("/teacherAllList")
    @ApiOperation("查询所有")
    public  R selelctAll(){
        return  R.success().data("teacherAll",eduTeacherService.selectAll()).message("成功");
    }
}

